<?php

namespace app\modules\sysConfig\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\sysConfig\models\Smstemplate;

/**
 * SmstemplateSearch represents the model behind the search form about `app\modules\sysConfig\models\Smstemplate`.
 */
class SmstemplateSearch extends Smstemplate
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['smstempltpk'], 'integer'],
            [['type', 'content', 'createtime', 'createuser'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Smstemplate::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'smstempltpk' => $this->smstempltpk,
            'createtime' => $this->createtime,
        ]);

        $query->andFilterWhere(['like', 'type', $this->type])
//            ->andFilterWhere(['like', 'smstempltpk', $this->smstempltpk])
            ->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'createuser', $this->createuser]);

        return $dataProvider;
    }
}
